// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/base/api/AlarmApi'

import ComClass from '@api/ComQuery'

import ListClass from '@api/base/model/AlarmQueryReq'
import OneClass from '@api/base/model/AlarmDetailQueryReq'
import EditClass from '@api/base/model/AlarmDealReq'
import BaseClass from '@api/base/model/MessageAlarmDto'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']
const BASE = [BaseClass, 'content']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = `查询${CORE.MAP.ALARM}列表`) {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const { comQuery, content } = await CORE.grpc(TIP, CLIENT, 'query', DTO)
    return [comQuery.totalCount, content]
  },
  async getRealList(param, TIP = `查询实时${CORE.MAP.ALARM}列表`) {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const { comQuery, content } = await CORE.grpc(TIP, CLIENT, 'queryRealtime', DTO)
    return [comQuery.totalCount, content]
  },
  async getHistoryList(param, TIP = `查询历史${CORE.MAP.ALARM}列表`) {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const { comQuery, content } = await CORE.grpc(TIP, CLIENT, 'queryHistory', DTO)
    return [comQuery.totalCount, content]
  },

  // —————————————————————————————— 详情 —————————————————————————————— //

  async detail(param, TIP = `查询实时${CORE.MAP.ALARM}详情`) {
    const DTO = CORE.grpcDTO(OneClass, param)
    const { content } = await CORE.grpc(TIP, CLIENT, 'detail', DTO)
    return [content]
  },

  // —————————————————————————————— 处理告警 —————————————————————————————— //

  async update(param, TIP = `处理${CORE.MAP.ALARM}`) {
    const DTO = CORE.grpcDTO(EditClass, param, BASE)
    await CORE.grpc(TIP, CLIENT, 'deal', DTO)
    return `${TIP}成功`
  },
}
